package com.realestate.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.realestate.constants.AppConstant;
import com.realestate.model.BrtbProduct;
import com.realestate.services.ProductService;

@Controller
public class InitController {
	
	@Autowired
	private ProductService productService;
	
	@RequestMapping(value = "/", method = RequestMethod.GET)
	public ModelAndView getdata() {

		List<BrtbProduct> listApartments = productService.getListproductByCategoryCode(AppConstant.APARTMENT, AppConstant.LIMIT);
		List<BrtbProduct> listHouses = productService.getListproductByCategoryCode(AppConstant.HOUSE, AppConstant.LIMIT);
		List<BrtbProduct> listVillas = productService.getListproductByCategoryCode(AppConstant.VILLA, AppConstant.LIMIT);
		List<BrtbProduct> listSApartments = productService.getListproductByCategoryCode(AppConstant.SERVICED_APARTMENT, AppConstant.LIMIT);
		List<BrtbProduct> listResorts = productService.getListproductByCategoryCode(AppConstant.RESORT, AppConstant.LIMIT);
		
		ModelAndView model = new ModelAndView("index");
		
		model.addObject("listApartments", listApartments);
		model.addObject("listHouses", listHouses);
		model.addObject("listVillas", listVillas);
		model.addObject("listSApartments", listSApartments);
		model.addObject("listResorts", listResorts);
		
		return model;

	}
}
